//
//  MRIndexViewController.m
//  MRDemo
//
//  Created by dingping on 2020/8/18.
//  Copyright © 2020 dingping. All rights reserved.
//

#import "MRIndexViewController.h"
#import "MRNestMainViewController.h"

@interface MRIndexViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *contentTableView;
@property (nonatomic, strong) NSArray *dataArray;

@end

@implementation MRIndexViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.title = @"MR主页";
    [self.view addSubview:self.contentTableView];
}

#pragma mark - init

- (UITableView *)contentTableView {
    if (!_contentTableView) {
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH) style:UITableViewStylePlain];
        tableView.backgroundColor = [UIColor whiteColor];
        tableView.delegate = self;
        tableView.dataSource = self;
        [tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
        _contentTableView = tableView;
    }
    return _contentTableView;
}

#pragma mark - delegate datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if(!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;

    NSDictionary *dict = self.dataArray[indexPath.row];
    NSString *str = [dict objectForKey:@"title"];
    cell.textLabel.text = str;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
        {
            MRNestMainViewController *mainVC = [[MRNestMainViewController alloc]init];
            [self.navigationController pushViewController:mainVC animated:YES];
        }
            break;
        case 1:
        case 2:
        case 3:
            break;

        default:
            break;
    }
}

- (NSArray *)dataArray {
    return @[
             @{
                 @"title" : @"ScrollView嵌套",
                 },
             @{
                 @"title" : @"半圆形弧形进度条",
                 },
             @{
                 @"title" : @"半圆形弧形进度条Test",
                 },
             @{
                 @"title" : @"折叠tableHeaderView自适应高度",
                 }
             ];
}


@end
